#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
struct Stu
{
	char name[20];
	int age;
	double score;
};
void swap(char* num1, char* num2, int width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char ret = 0;
		ret = *num1;
		*num1 = *num2;
		*num2 = ret;
		num1++;
		num2++;
	}
}
void my_qsort(void* base, int num, int width, int (*cmp)(const void* e1, const void* e2))
{
	int i = 0;
	for (i = 0; i < num - 1; i++)
	{
		int j = 0;
		for (j = 0; j < num - 1 - i; j++)
		{
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width) > 0)
			{
				swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}
int cmp_int(const void* e1, const void* e2)
{
	return *(int*)e1 - *(int*)e2;
}
int cmp_stu_name(const void* e1, const void* e2)
{
	return strcmp(((struct Stu*)e1)->name, ((struct Stu*)e2)->name);
}
int main()
{
	//struct Stu arrstu[3] = { {"zhangsan",18,56.4},{"lisi",22,78.9},{"wangwu",30,80.2}};
	//int sz = sizeof(arrstu) / sizeof(arrstu[0]);
	//my_qsort(arrstu, sz, sizeof(arrstu[0]), cmp_stu_name);
	int arr[] = { 9,8,7,6,5,4,3,2,1,0 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	my_qsort(arr, sz, sizeof(arr[0]), cmp_int);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}
